package titt.head.request;

import titt.TITTValues;
import titt.head.HTTPHead;
import titt.head.HeadFactory;
import titt.head.util.AbstractHead;

public class Request extends AbstractHead implements RequestHead {

	public Request(HTTPHead h) {
		super.h = h;
	}
	
	public Request(int method, String path, HTTPHead h) {
		if(!path.startsWith("/")) path = "/" + path;
		super.h = HeadFactory.createHead(h, TITTValues.methodAsString(method) + " " + path + " HTTP/1.1");
	}
	
	@Override
	public int getHTTPMethod() {
		String method = h.getStatusLine().split(" ")[0];
		
		if(method.equals("GET")) return TITTValues.GET;
		if(method.equals("POST")) return TITTValues.POST;
		if(method.equals("OPTIONS")) return TITTValues.OPTIONS;
		
		return -1;
	}

	@Override
	public String getPath() {
		return h.getStatusLine().split(" ")[1];
	}

}
